import 'package:flutter/material.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/core/http/http.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/data/entities/home/enterprise/enterprise_staff_entity_entity.dart';

import '../../../../app/core/core.dart';

/// 一企一档-人员证件照-详情
class PeopleDetails extends StatefulWidget {
  const PeopleDetails({super.key});

  @override
  State<PeopleDetails> createState() => _PeopleDetailsState();
}

class _PeopleDetailsState extends State<PeopleDetails> {

  EnterpriseStaffEntityEntity item = Get.arguments as EnterpriseStaffEntityEntity;

  /// 获取详情
  void getDetails() async {
    final res = await HttpUtil().generateGetRequest<EnterpriseStaffEntityEntity>(
      '${Interface.mainBaseUrl}/admin-api/system/enterprise-staff/get',
      queryParameters: {
        'id': item.id,
      },
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        item = result.data!;
        setState(() {

        });
      }
    });
  }

  @override
  void initState() {
    super.initState();
    getDetails();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        titleText: '人员及证件照详情',
      ),
      body: Column(
        children: [
          CustomTitleChartPage(
            title: item.companyName,
            child: itemWeight(item),
          )
        ],
      ),
    );
  }

  Widget _title(String title, String? value) {
    return Row(
      children: [
        Text(
          '$title：',
          style: TextStyle(
            fontSize: 14.sp,
            fontWeight: FontWeight.w400,
            color: const Color(0xFFC7CEE5),
          ),
        ),
        Expanded(
          child: Align(
            alignment: Alignment.centerLeft,
            child: Text(
              value ?? '空',
              style: TextStyle(
                fontSize: 14.sp,
                fontWeight: FontWeight.w400,
                color: const Color(0xFF1D3452),
              ),
            ),
          ),
        ),
      ],
    );
  }

  Widget itemWeight(EnterpriseStaffEntityEntity item) {
    //对象
    return Column(
      children: [
        Row(
          children: [
            Expanded(child: _title('部门', item.deptName??'')),
            Expanded(child: _title('班组', item.teamName??'')),
          ],
        ),
        AppGaps.vGap8,
        Row(
          children: [
            Expanded(child: _title('姓名', item.staffName??'')),
            Expanded(child: _title('员工编号', item.archiveNumber??'')),
          ],
        ),
        AppGaps.vGap8,
        Row(
          children: [
            Expanded(child: _title('性别', item.sex==1?'男':'女')),
            Expanded(child: _title('岗位（工种）',item.jobName??'')),
          ],
        ),
        AppGaps.vGap8,
        _title('出生年月', item.birthTime),
        AppGaps.vGap8,
        _title('身份证号', item.idCard),
        AppGaps.vGap8,
        _title('联系电话', item.phoneNumber),
        AppGaps.vGap8,
        _title('学历', item.educationId.toString()),
        AppGaps.vGap8,
        _title('入厂时间', item.startWorkingTime),
        AppGaps.vGap8,
        _title('是否为特殊工种', item.isSpecialJob == true ? '是' : '否'),
        AppGaps.vGap8,
        _title('三（四）级安全教育', item.isSafeEducation == true ? '是' : '否'),
        AppGaps.vGap8,
        // _title('职业技能等级', item.riskLevel ?? ''),
        _title('是否发生安全生产事故', item.isAccident == true ? '是' : '否'),
        AppGaps.vGap8,
        _title('事故情况简述', item.accidentDescription),
        AppGaps.vGap8,
        _title('工伤情况', item.isSpecialStaff == true ? '是' : '否'),
        AppGaps.vGap8,
        _title('是否从事有害及尘毒作业', item.isSpecialDeviceStaff == true ? '是' : '否'),

      ],
    );
  }

}
